import React, { useState } from 'react';

const Vote = (props) => {
    let {title}=props
    let [supNum, setSupNum]= useState(0)
    let [oppNum, setOppNum]=useState(0)

    return (
        <div className='vote-box'>
            <div className='header'>
                <h1>{title}</h1>
                <span>{oppNum+supNum}人</span>
            </div>
            <div className='main'>
                <p>支持人数:{supNum}人</p>
                <p>支持人数:{oppNum}人</p>
            </div>
            <div className='footer'>
                <button onClick={()=>{setSupNum(supNum+1)}}>支持</button>
                <button onClick={()=>{setOppNum(oppNum+1)}}>反对</button>
                
            </div>
        </div>
    );
};

export default Vote;

class Parent{
    constructor(x,y){
        this.total=x+y
    }
    num=200;//等价于this.num=200, 给实例添加私有属性
    getNum=()=>{
        //箭头函数没有自己的this;箭头的this是指向类实例本身
        console.log(this);       
    }
    sum(){

    }
    func=function(){}
    static average(){}
}

let p=new Parent(10,20);
console.log(p);
